--Clint
--Deleting cDivsion column in all tables in Comunion

declare @cTableName varchar(30),
		@cField varchar (25),
		@sql varchar (3000)

DECLARE Cur_PM CURSOR FOR
	SELECT t.name AS table_name,
	c.name AS column_name
	FROM sys.tables AS t
	INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
	WHERE c.name LIKE '%cDivision'
	ORDER BY table_name
	OPEN Cur_PM

FETCH NEXT FROM Cur_PM INTO @cTableName, @cField
WHILE @@FETCH_STATUS = 0

BEGIN

set @sql = 'ALTER TABLE '''+@cTableName+''' DROP COLUMN '''+@cfield+''''
print @sql
exec @sql	
	
FETCH NEXT FROM Cur_PM INTO @cTableName, @cField

END

DEALLOCATE Cur_PM
